package grid.puzzle.util;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import grid.puzzle.GridAdapter;
import grid.puzzle.GridPuzzleActivity;

public class AnimatedView extends View
  implements Animation.AnimationListener
{
  public static final int DEFAULT_ANIMATION_DURATION = 500;
  private int itemIdx;
  private BaseAdapter mAdapter;
  private Animation mAnimation;
  private AnimateDrawable mDrawable;
  private RelativeLayout topContainer;

  public AnimatedView(Context paramContext, BaseAdapter paramBaseAdapter, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6)
  {
    super(paramContext);
    setFocusable(true);
    setFocusableInTouchMode(true);
    this.itemIdx = paramInt1;
    this.mAdapter = paramBaseAdapter;
    Drawable localDrawable = paramContext.getResources().getDrawable(paramInt2);
    localDrawable.setBounds(0, 0, localDrawable.getIntrinsicWidth(), localDrawable.getIntrinsicHeight());
    this.mAnimation = new TranslateAnimation(paramInt3, paramInt4, paramInt5, paramInt6);
    this.mAnimation.setDuration(500L);
    this.mAnimation.initialize(((GridAdapter)this.mAdapter).getItemWidth(), ((GridAdapter)this.mAdapter).getItemHeight(), ((GridAdapter)this.mAdapter).getItemWidth(), ((GridAdapter)this.mAdapter).getItemHeight());
    this.mDrawable = new AnimateDrawable(localDrawable, this.mAnimation);
    this.mAnimation.setAnimationListener(this);
  }

  public void onAnimationEnd(Animation paramAnimation)
  {
    setVisibility(4);
    ((GridAdapter)this.mAdapter).setItemMoving(this.itemIdx, false);
    this.mAdapter.notifyDataSetChanged();
  }

  public void onAnimationRepeat(Animation paramAnimation)
  {
  }

  public void onAnimationStart(Animation paramAnimation)
  {
  }

  protected void onDraw(Canvas paramCanvas)
  {
    this.mDrawable.draw(paramCanvas);
    invalidate();
  }

  public void startAnimation()
  {
    Context localContext = getContext();
    if ((localContext instanceof GridPuzzleActivity))
    {
      this.topContainer = ((RelativeLayout)((GridPuzzleActivity)localContext).findViewById(2131034113));
      this.topContainer.addView(this);
      this.mAnimation.startNow();
    }
  }
}